/**
 * 
 */
package org.bankabeule.ui.editors;

import org.bankabeule.Account;
import org.bankabeule.ui.Activator;
import org.bankabeule.util.Utils;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement;

/**
 * @author sdudoit
 *
 */
public class AccountEditorInput implements IEditorInput {

	
	/**
	 * Account
	 */
	private Account account = null;

	
	/**
	 * Constructor
	 */
	public AccountEditorInput(Account editAccount) {
		account = editAccount;
	}

	
	/**
	 * Get account
	 */
	public Account getAccount() {
		return account;
	}
	

	/* (non-Javadoc)
	 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
	 */
	public ImageDescriptor getImageDescriptor() {
		return Activator.getImageDescriptor("icons/sample.gif"); //$NON-NLS-1$
	}

	
	/* (non-Javadoc)
	 * @see org.eclipse.ui.IEditorInput#getName()
	 */
	public String getName() {
		if (account != null) {
			return Utils.getDisplay(account);
		} else {
			return null;
		}
	}
	
	
	/* (non-Javadoc)
	 * @see org.eclipse.ui.IEditorInput#exists()
	 */
	public boolean exists() {
		return account != null;
	}
	
	
	/* (non-Javadoc)
	 * @see org.eclipse.ui.IEditorInput#getPersistable()
	 */
	public IPersistableElement getPersistable() {
		return null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.IEditorInput#getToolTipText()
	 */
	public String getToolTipText() {
		if (account != null) {
			return "Editing account : " + Utils.getDisplay(account);
		} else {
			return null;
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
	 */
	@SuppressWarnings("unchecked")
	public Object getAdapter(Class adapter) {
		return null;
	}


	@Override
	public boolean equals(Object arg0) {
		if (arg0 instanceof AccountEditorInput) {
			if (((AccountEditorInput)arg0).getAccount().equals(account)) {
				return true;
			}
		}
		return super.equals(arg0);
	}

}
